﻿using PARK.Common.Const;
using SqlSugar;
using System;
using Yitter.IdGenerator;

namespace PARK.Consumer.Entity
{
    /// <summary>
    /// 管理退款
    /// </summary>
    [SugarTable("consum_refund")]
    [Tenant(ClaimConst.TENANT_ID)]
    public class ConsumRefundEntity
    {
        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "taskId", IsPrimaryKey = true)]
        public string taskId { get; set; }
        /// <summary>
        /// 原充值单Id
        /// </summary>
        [SugarColumn(ColumnName = "rechargeId")]
        public string rechargeId { get; set; }
        /// <summary>
        /// 原支付交易对应的商户订单号
        /// </summary>
        [SugarColumn(ColumnName = "out_trade_no")]
        public string out_trade_no { get; set; }
        /// <summary>
        /// 微信支付交易订单号
        /// </summary>
        [SugarColumn(ColumnName = "transaction_id")]
        public string transaction_id { get; set; }
        /// <summary>
        /// 原支付金额
        /// </summary>
        [SugarColumn(ColumnName = "totalAmt")]
        public decimal totalAmt { get; set; }
        /// <summary>
        /// 退款金额
        /// </summary>
        [SugarColumn(ColumnName = "refundAmt")]        
        public decimal refundAmt { get; set; }
        /// <summary>
        /// 是否已退款 1是0否
        /// </summary>
        [SugarColumn(ColumnName = "IsRefund")]
        public int IsRefund { get; set; } = 0;
        /// <summary>
        /// 退款时间
        /// </summary>
        [SugarColumn(ColumnName = "RefundDate")]        
        public DateTime? RefundDate { get; set; }
        /// <summary>
        /// 商户系统内部的退款单号，商户系统内部唯一
        /// </summary>
        [SugarColumn(ColumnName = "out_refund_no")]
        public string out_refund_no { get; set; }
        /// <summary>
        /// 微信支付退款号
        /// </summary>
        [SugarColumn(ColumnName = "refund_id")]        
        public string refund_id { get; set; }
        /// <summary>
        /// 退款结果
        /// </summary>
        [SugarColumn(ColumnName = "refundStatus")]        
        public string refundStatus { get; set; }
        
        /// <summary>
        /// 摘要信息
        /// </summary>
        [SugarColumn(ColumnName = "Summary")]        
        public string Summary { get; set; }
        
        /// <summary>
        /// 创建人Id
        /// </summary>
        [SugarColumn(ColumnName = "CreateUser")]        
        public string CreateUser { get; set; }
        
        /// <summary>
        /// 创建人姓名
        /// </summary>
        [SugarColumn(ColumnName = "CreateUserName")]        
        public string CreateUserName { get; set; }
        
        /// <summary>
        /// 创建日期
        /// </summary>
        [SugarColumn(ColumnName = "CreateDate")]        
        public DateTime? CreateDate { get; set; }       
        
        /// <summary>
        /// 入库时间
        /// </summary>
        [SugarColumn(ColumnName = "DbDate")]        
        public DateTime? DbDate { get; set; }       

        /// <summary>
        /// 消费卡号 
        /// </summary>
        [SugarColumn(ColumnName = "CardNo")]
        public string CardNo { get; set; }
        /// <summary>
        /// 卡面卡号 
        /// </summary>
        [SugarColumn(ColumnName = "CatCardNo")]
        public string CatCardNo { get; set; }        
        /// <summary>
        /// 用户Id
        /// </summary>
        [SugarColumn(ColumnName = "EmployeeId")]
        public string EmployeeId { get; set; }

        /// <summary>
        /// 工号
        /// </summary>
        [SugarColumn(ColumnName = "JobNo")]
        public string JobNo { get; set; }

        /// <summary>
        /// 姓名
        /// </summary>
        [SugarColumn(ColumnName = "ReallName")]
        public string ReallName { get; set; }

        /// <summary>
        /// 部门Id
        /// </summary> 
        [SugarColumn(ColumnName = "DepartId")]       
        public string DepartId { get; set; }
        /// <summary>
        /// 部门
        /// </summary>
        [SugarColumn(ColumnName = "DepartName")]        
        public string DepartName { get; set; }
        /// <summary>
        /// 所属公司Id
        /// </summary>
        [SugarColumn(ColumnName = "CompanyId")]
        public string CompanyId { get; set; }

        /// <summary>
        /// 公司名称
        /// </summary>
        [SugarColumn(ColumnName = "CompanyName")]
        public string CompanyName { get; set; }

        /// <summary>
        /// 是否已执行退款
        /// </summary>
        [SugarColumn(ColumnName = "IsAny")]
        public int? IsAny { get; set; }
        /// <summary>
        /// 申请退款时间
        /// </summary>
        [SugarColumn(ColumnName = "AuditDate")]
        public DateTime AuditDate { get; set; }

        /// <summary>
        /// 是否需要退款 1是0否
        /// </summary>
        [SugarColumn(ColumnName = "IsNeedRefund")]
        public int? IsNeedRefund { get; set; }

        /// <summary>
        /// 销户状态 0 无需退款；1 等待退款；2 退款处理中；3 退款成功；4 转入退款；5 退款异常
        /// </summary>
        [SugarColumn(ColumnName = "billStatus")]
        public int? billStatus { get; set; }
        /// <summary>
        /// 销户状态名称
        /// </summary>
        [SugarColumn(ColumnName = "billStatusName")]
        public string billStatusName { get; set; }


        /// <summary>
        /// 是否主销户退款单
        /// </summary>
        [SugarColumn(ColumnName = "IsMain")]
        public int? IsMain { get; set; }
        
        /// <summary>
        /// 创建
        /// </summary>
        public virtual void Create()
        {
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.taskId = YitIdHelper.NextId().ToString();
            this.CreateDate = DateTime.Now;
            this.IsMain = 1;
            if (!string.IsNullOrEmpty(userId))
            {
                this.CreateUser = CreateUser == null ? userId : CreateUser;
                this.CreateUserName = CreateUserName == null ? userName : CreateUserName;
            }
        }
    }
}